package dao;

import java.util.List;
import model.Discipline;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

/**
 *
 * @author Moraes
 */
public class DisciplineDAO {

    private SqlSessionFactory sqlSessionFactory;

    public DisciplineDAO() {
        this.sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
    }

    public Discipline selectById(int pIdDiscipline) {
        SqlSession session = sqlSessionFactory.openSession();
        try {
            Discipline discipline = (Discipline) session.selectOne("Discipline.getById", pIdDiscipline);
            return discipline;
        } finally {
            session.close();
        }
    }

    public List<Discipline> selectAll() {
        SqlSession session = sqlSessionFactory.openSession();
        List<Discipline> disciplineList;
        try {
            disciplineList = session.selectList("Discipline.getAll");
            return disciplineList;
        } finally {
            session.close();
        }
    }

    public void Insert(Discipline pDiscipline) {
        SqlSession session = sqlSessionFactory.openSession();
        try {
            session.insert("Discipline.insert", pDiscipline);
            session.commit();
        } finally {
            session.close();
        }
    }
}
